import React, { Component } from 'react';
import { connect } from 'dva';
import router from 'umi/router';
import { PageLoading } from '@ant-design/pro-layout';
import memoryUtils from '@/utils/memoryUtils';
import { findFirstNode } from '@/utils/funcUtils';

class index extends Component {

  render() {
    const { subSystems, title, enTitle, footer } = this.props;
    if(!subSystems || subSystems.length === 0) {
      return <PageLoading/>;
    }
    memoryUtils.title = title;
    memoryUtils.enTitle = enTitle;
    memoryUtils.footer = footer;
    const initSubSystem = findFirstNode(subSystems);
    // if(subSystems[0].children && subSystems[0].children.length > 0) {
    //   firstSubsystem = subSystems[0].children[0];
    // }
    // // const path = ((subSystems[0].modules.length < 2)?'/subSystem1/':'/subSystem/') + subSystems[0].$handle;
    // const path = ((firstSubsystem.modules.length < 2)?'/subSystem1/':'/subSystem/') + firstSubsystem.$handle;
    // router.push(path);

    if(initSubSystem) {
      let path = '/subSystem/' + initSubSystem.$handle;
      if(initSubSystem.modules && initSubSystem.modules.length > 0) {
        const initSubModule = findFirstNode(initSubSystem.modules);
        if(initSubModule) {
          path += '/' + initSubModule.$handle;
        }
      }
      memoryUtils.headerIndex = [];
      router.push(path);
    }
    return false;
  }
}

export default connect(({ tlsWebServer }) => ({
  ...tlsWebServer,
}))(index);
